<template>
	<box :x="aniInfo.x" :y="aniInfo.y">
		<ani :src="aniInfo.src" @complete="aniPlayComplete" loop="true" :time="aniInfo.time" y="15"></ani>
		<txt :text="info.name" x="10" y="40" size="14" color="#FFFFFF"></txt>
		<img src="res/ui/bloodTop2.png" width="32" height="4" x="8" y="0"></img>
	</box>
</template>

<script>
init(){
	//只对已定义的对象做监听处理,如需监听新对象,需定义一个初始值,子集定义了啥监听啥,不定义子集不做监听处理
	this.info= {
		name: "玩家名",
		level: 255,
		status: 0,//0站立 1行走 2跑步 3物理 4魔法 5死亡
		dir: 4,//移动方向
		body: 3,//人物外观,主要用于区分多个资源
		mapId: 3,//地图代码
		x: 185,//地图坐标
		y: 95,//地图坐标
		
	};
	this.config = {
		standTime: 1,//站立动画循环时间 (秒)
		walkTime: 0.6,//走路动画循环时间 (秒)
		runTime: 0.7,//跑步动画循环时间 (秒)
	};
	this.aniInfo = {
		x: 375,
		y: 245,
		time: this.config.standTime,//动画周期播放间隔 (秒)
		src: "res/ani/" + this.info.body + "/man_"+ this.info.status +"_"+ this.info.dir +".json",
	};
}

create() {
	console.log("player create");
	if(this.self){
		MAP.loadMap(this.info.mapId, this.info.x, this.info.y);
	}else{
		let point = MAP.pointToScreen(this.info.x, this.info.y);
		this.aniInfo.x = point.x;
		this.aniInfo.y = point.y;
		console.log("players");
	}
}

update(delta) {

}

destroyed() {
	
}

move(x, y) {
	this.info.x = Math.ceil(x);
	this.info.y = Math.ceil(y);
    MAP.loadMap(this.info.mapId, x, y);
}

updatePlayerAni(dir, status) {
	this.info.dir = dir;
	this.info.status = status;
	if(this.info.status == 0){
		this.aniInfo.time = this.config.standTime;
	}else if(this.info.status == 1){
		this.aniInfo.time = this.config.walkTime;
	}else if(this.info.status == 2){
		this.aniInfo.time = this.config.runTime;
	}else{
		this.aniInfo.time = this.config.standTime;
	}
	this.aniInfo.src = "res/ani/" + this.info.body + "/man_"+ this.info.status +"_"+ this.info.dir +".json";
}

aniPlayComplete(){
	if(!MAP.keepMove && (this.info.status == 1 || this.info.status == 2)){//人物移动动画完成恢复站立姿势
		setTimeout(() => {
			this.info.status = 0;
			this.aniInfo.time = this.config.standTime;
			this.aniInfo.src = "res/ani/" + this.info.body + "/man_"+ this.info.status +"_"+ this.info.dir +".json";
		}, this.aniInfo.time / 6 * 1000);//最后一帧稍做停留  单帧时间  跑或走 总时间除以6帧
	}
}

</script>